<?php
/**
 * Created by PhpStorm.
 * User: 50223
 * Date: 18.7.25
 * Time: 15:07
 */
namespace App\Http\Controllers\Verify;

use App\Http\Controllers\Controller;
use App\Models\Order;
use App\Models\Elsearch;
use Illuminate\Http\Request;

class VerifyController extends Controller{

	public $_model_order = null;
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->_model_order = new Order();
    }
    public function verifyList(Request $request){
    	$get = $request->all();
    	$rs = array();
    	$rs['list'] = $this->_model_order->get_order_verify_list($get);
        $rs['list']->appends($get);
        $rs['size'] = $rs['list']->total();
        $rs['page'] = $rs['list']->links();
        $rs['list'] = $rs['list']->toArray()['data'];
        // print_rf($rs['list']);die();
        return view('order_verify/list_'.$get['p'], ['rs'=>$rs]);
    }
    public function verifyPic(Request $request){
    	$get = $request->all();
    	$field = $get['field'];
    	$rs = array();
    	$rs['type'] = 'material';
        if($field == 'shop_card'){
        	$shop_card_id = $this->_model_order->get_order_material_by_order_id($get['id'])->shop_card_id;
        	$data = $this->_model_order->get_shop_card_by_id($shop_card_id);
        	$rs['pic'] = explode(',', $data->pic);
        }elseif($field == 'transport'){
        	$rs = $get;
        	return view('order_verify/upload_transport', ['rs'=>$rs]);
        }elseif($field == 'transport_proxy' || $field == 'transport_contract' || $field == 'buy_card' || $field == 'illustrate'){
        	$data = $this->_model_order->get_order_material_by_order_id($get['id']);
        	if($field == 'transport_contract'){
        		$field = 'contract';
        		$rs['type'] = 'contract';
        	}
        	$rs['pic'] = explode(',', $data->$field);
        	// print_rf($rs);
        }else{
        	$data = $this->_model_order->get_order_info_by_order_id($get['id']);
        	$data = $this->_model_order->get_order_basic_by_id($data->order_basic_id);
        	if($field == 'dcs_card'){
        		$data = $this->_model_order->get_cust_material($data->cust_id,array($field,'dcs_card_attach'));
        		$data->$field = $data->$field .= ','.$data->dcs_card_attach;
        	}else{
        		$data = $this->_model_order->get_cust_material($data->cust_id,array($field));
        	}
        	
        	$rs['pic'] = explode(',', $data->$field);
        }
        
    	return view('order_verify/pic_verify', ['rs'=>$rs]);
    }
    public function verifyMatreial(Request $request){
    	$post = $request->all();
    	$field = $post['field'];
    	$order = $this->_model_order->get_order_info_by_order_id($post['id']);
        $basic_order = $this->_model_order->get_order_basic_by_id($order->order_basic_id);
        $this->_model_order->verify_cust_material($basic_order->cust_id,$field,$post,$order);	
        $this->_model_order->after_verify_status($basic_order,$order);
        echo 1;
    }
    public function verifyMatreialFail(Request $request){
    	$post = $request->all();
    	$field = $post['field'];
    	$data = $this->_model_order->get_order_info_by_order_id($post['id']);
        $data = $this->_model_order->get_order_basic_by_id($data->order_basic_id);
        $data = $this->_model_order->verify_cust_materialFail($data->cust_id,$field,$post['remark']);

    }
}